package com.common.pattern.pipeline.handler.impl;

import com.common.pattern.pipeline.bo.BusinessContext;
import com.common.pattern.pipeline.handler.ContextHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @Author: xuxiang
 * @Date: 2023-8-10
 * @Description: 生产场地检测（管道处理器）
 */
public class ContextFactoryHandler implements ContextHandler<BusinessContext> {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public boolean handle(BusinessContext context) {
        Map<String, Object> formInput = context.getInputParams();

        if ((CollectionUtils.isEmpty(formInput))) {
            context.setFailureMsg("业务输入数据不能为空");
            return false;
        }
        //模拟业务逻辑

        String content = (String) formInput.get("factory");
        if (!StringUtils.hasText(content)) {
            context.setFailureMsg("未获取到产品生产场地");
            return false;
        }

        //业务逻辑省略

        return true;
    }
}